package com.xbq.exceleditor.bean.viewmodel

import android.content.Context
import androidx.lifecycle.ViewModel
import com.xbq.exceleditor.R
import com.xbq.exceleditor.utils.FeatureEnum
import com.xbq.exceleditor.utils.formatFeatures
import com.xbq.xbqsdk.net.constants.SysConfigEnum
import com.xbq.xbqsdk.net.userCache
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

/**
 * Author: liaohaiping
 * Time: 2020-11-10
 * Description:
 */
@HiltViewModel
class MineViewModel @Inject constructor(@ApplicationContext val context: Context) : ViewModel() {
    var logined = false
    var userName = ""
    var uId = ""
    var vip = false
    var vipExpireTime = ""
    var buyVipText = ""
    var ischarge =false

    fun initUserInfo() {
        logined = userCache.isLogin()
        ischarge = userCache.getConfigBoolean(SysConfigEnum.IS_CHARGE)
        if (logined) {
            val loginData = userCache.getLoginData()
            userName = "帐号: ${loginData!!.userName}"
            uId = "用户ID: ${loginData!!.id}"
            vip = loginData.canUse(FeatureEnum.EXCEL_EDITOR.name)
            buyVipText = context.resources.getString(R.string.renew_vip)
            vipExpireTime= loginData.formatFeatures()
        }else{
            userName =context.resources.getString(R.string.not_login)
            uId=  context.resources.getString(R.string.login_can_use_more_functions)
            buyVipText= context.resources.getString(R.string.subscribe_immediately)
            vip=false
            vipExpireTime=""
        }
    }

}